<template>
	<view>
		<view class="cu-bar foot input" :style="[{bottom:inputBottom+'px'}]">
			<view class="action">
				<text class="cuIcon-sound text-grey"></text>
			</view>
			<input class="solid-bottom" value="" :adjust-position="false" :focus="false" maxlength="300" cursor-spacing="10" v-model="inputValue" @input="onInput" @confirm="send" @focus="InputFocus" @blur="InputBlur" :placeholder="placeholder"></input>
			<view class="action">
				<text class="cuIcon-emojifill text-grey"></text>
			</view>
			<button v-if="userInfo.nickname" class="cu-btn bg-green shadow" @click="send">发送</button>
			<!-- #ifndef H5 -->
			<!-- 注意@getuserinfo要小写 "JSON.stringify(userInfo) == {}"-->
			<button v-else class="cu-btn bg-green shadow" open-type="getUserInfo" @getuserinfo="onGetUserInfo">发送2</button>
			<!-- #endif -->
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			inputBottom:{
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				inputValue: '',
				userInfo: {},
				// placeholder: '好像说点什么呀···'
			};
		},
		computed:{
			replyNickName: function(){
				return this.replyUserInfo.nickname || ''
			},
			placeholder: function(){
				return '回复' + this.replyUserInfo.nickname
			}
		},
		created() {
			const userInfo = {
				"userName": "yuanlei",
				"classNumber": 1,
				"className": "2班",
				"identifier": "1班苑磊_B53628E0296D88F2_ss",
				"nickname": "yuan"
			};
			// this.replyUserInfo;
			uni.setStorageSync('userInfo', userInfo);
			this.userInfo = uni.getStorageSync("userInfo") || {};
			console.log('add--created----',uni.getStorageSync("userInfo").nickname)
		},
		mounted() {
			console.log('add--onShow')
			console.log('add--created----',uni.getStorageSync("userInfo").nickname)
		},
		methods:{
			onInput(e){
				console.log(e.detail)
				const {value} = e.detail;
				this.inputValue = value;
			},
			// 发表评论
			send(){
				this.$emit('addComment', this.inputValue, this.userInfo)
			},
			// 获取微信用户信息
			onGetUserInfo(e){
				console.log('3333333333',e);
				const {userInfo} = e.detail;
				this.userInfo = userInfo;
				
			},
			InputFocus(e) {
				console.log(e.detail.height)
				this.inputBottom = e.detail.height || 0;
			},
			InputBlur(e) {
				this.inputBottom = 0
			},
			// 清空输入框
			clearInput(){
				this.inputValue = '';
			},
			// 设置输入框placeholder
			setPlaceholder(text){
				this.placeholder = text;
			},
		}
	}
</script>

<style lang="less">

</style>
